﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using SharpSvn;

namespace SvnList
{
    class Lib
    {
        public void CheckDir(string targetPath, StringBuilder urls)
        {
            if (string.Compare(new DirectoryInfo(targetPath).Name, ".svn", true) == 0)
                return;

            bool hassvnUrl = false;
            using (SvnClient client = new SvnClient())
            {
                var uri = client.GetUriFromWorkingCopy(targetPath);
                if (uri != null)
                {
                    hassvnUrl = true;
                    urls.Append(targetPath).Append("\t\t\t\t").Append(uri.ToString()).AppendLine();
                }
                else
                {
                    if (client.Upgrade(targetPath))
                    {
                        hassvnUrl = true;
                    }
                    else
                        hassvnUrl = false;
                }
            }
            if (!hassvnUrl)
            {
                var dirs = Directory.GetDirectories(targetPath);
                foreach (var dir in dirs)
                {
                    CheckDir(dir, urls);
                }
            }
        }
    }
}
